package com.huzz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huzz.entity.SysPermission;
import com.huzz.model.PermissionModel;
import com.huzz.service.ISysPermissionService;
import com.huzz.vo.PermissionVO;
import com.huzz.util.body.JsonResult;
import com.huzz.util.body.ResultTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Name 名称
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-04-2023/4/27 14:34
 */
@Api(tags = "系统权限模块 API")
@RestController
@RequestMapping("/api/permission")
public class SysPermissionController {

    @Autowired
    private ISysPermissionService permissionService;

    @ApiOperation(value = "新建权限")
    @PostMapping("/createPermission")
    public JsonResult<String> createPermission(@RequestBody @Validated PermissionModel permissionModel) {
        return ResultTool.response(permissionService.createPermission(permissionModel));
    }

    @ApiOperation(value = "查询权限分页列表")
    @PostMapping("/findPermissionListPage")
    public JsonResult<IPage<PermissionVO>> findPermissionListPage(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, PermissionModel model) {
        return ResultTool.success(permissionService.findPermissionListPage(pageNum, pageSize, model));
    }

    @ApiOperation(value = "编辑权限")
    @PutMapping("/updatePermissionById")
    public JsonResult<String> updatePermissionById(@RequestBody SysPermission permission) {
        return ResultTool.response(permissionService.updatePermissionById(permission));
    }

    @ApiOperation(value = "删除权限")
    @DeleteMapping("/removePermissionById")
    public JsonResult<String> removePermissionById(@RequestParam Integer id) {
        return ResultTool.response(permissionService.removePermissionById(id));
    }

}
